﻿using System;
using System.IO;
using System.Text;
namespace Common
{
    public class FileHelper
    {

        /// <summary>
        /// 目录是否存在
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static bool IsExistDirectory(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return false;
            }
            return Directory.Exists(path);
        }
        /// <summary>
        /// 检测文件是否存在
        /// </summary>
        /// <param name="filepath">文件路径</param>
        /// <returns></returns>
        public static bool IsExistFile(string filepath)
        {
            if (string.IsNullOrEmpty(filepath))
            {
                return false;
            }
            return File.Exists(filepath);
        }
        /// <summary>
        /// 获取目录中的文件列表
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static string[] GetFiles(string path)
        {
            if(string.IsNullOrEmpty(path))
            {
                throw new ArgumentException("请输入参数");
            }
            if (!IsExistDirectory(path))
            {
                throw new FileNotFoundException();
            }
            return Directory.GetFiles(path);
        }
    }
}
